﻿using Microsoft.AspNetCore.SignalR;
using Snake.Common;

namespace Snake.Server
{
    public class SnakeHub : Hub
    {
        /// <summary>
        /// 向客户端发送游戏状态
        /// </summary>
        /// <param name="gameState"></param>
        /// <param name="snakeStates"></param>
        /// <returns></returns>
        public async Task SendGameState(GameState gameState,List<SnakeState> snakeStates)
        {
            if (Clients != null)
            {
                await Clients.Group(gameState.GameId).SendAsync("ReceiveGameState", gameState,snakeStates);
            }
        }
        /// <summary>
        /// 加入游戏中
        /// </summary>
        /// <param name="gameId"></param>
        /// <returns></returns>
        public async Task JoinGame(string gameId)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, gameId);
        }
    }
}
